<meta charset="UTF-8"/>
<?php

$filename = 'user.dat';

$name = $_POST['name'];
$pwd = $_POST['pwd'];

//判断注册是否重复
$uses = array();
//***************************
$struser = file_get_contents($filename);
$usersstr = explode("\n", $struser);
foreach ($usersstr as $v) {
	$temp = explode("\t", $v);
	if (count($temp) == 2) {
		$tempname = $temp[0];
		$temppwd = $temp[1];
		$uses[$tempname] = $temppwd;
	}
}
//***************************

if (isset($uses[$name])) {
	echo '该用户已经注册';
} else {
	$data = $name . "\t" . $pwd . "\n";

	file_put_contents($filename, $data, FILE_APPEND);
	echo '注册成功！';
}
?>
